package org.foreningsgatan.genetics;

import java.io.Serializable;

public class DecisionNode<T extends Serializable, S extends Serializable> extends MultipleNode<T, S> implements Cloneable {
	protected float limit;
	protected T dataSource;
	
	protected DecisionNode(T dataSource, float limit) {
		this.dataSource = dataSource;
		this.limit = limit;
	}
	
	@Override
	protected void perform(SimulationEnvironment<T, S> environment) {
		if (environment.read(dataSource) > limit) {
			leftNode.perform(environment);
			rightNode.perform(environment);
		}
	}
	
	@Override
	protected Node<T, S> clone() {
		DecisionNode<T, S> clone = (DecisionNode<T, S>) super.clone();
		clone.dataSource = dataSource;
		clone.limit = limit;
		
		return clone;
	}
}
